package com.photoeditor.demo.ui.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class ScrollLimitViewPager extends ViewPager {

    private boolean mCanScroll = true;

    public ScrollLimitViewPager(Context context) {
        super(context);
    }

    public ScrollLimitViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setCanScroll(boolean canScroll) {
        this.mCanScroll = canScroll;
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        try {
            if (mCanScroll) {
                return super.onTouchEvent(arg0);
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        try {
            if (mCanScroll) {
                return super.onInterceptTouchEvent(arg0);
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }
}
